<template>
    <div>
        <el-form style="width: 60%" :model="tableData" :rules="rules" ref="tableData" label-width=100px class="demo-ruleForm">
            <el-form-item label="学院ID" prop="id">
                <el-input v-model="tableData.id" readonly></el-input>
            </el-form-item>
            <el-form-item label="名称" prop="name">
                <el-input v-model="tableData.name" ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submit('tableData')">修改</el-button>
                <el-button @click="reset('tableData')">重置</el-button>
                <el-button @click="back()">返回</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "UpdateTMajor",
        created() {
            const _this =this;
            axios.get('http://localhost:8181/teacher/findMajorByID/'+this.$route.query.id).then(function (resp) {
                _this.tableData=resp.data
            })
        },
        data(){
            return{
                tableData:[
                    {
                        id:'',
                        name:''
                    }
                ],
                rules:{
                    name:[
                        {
                            required: true,
                            message: '名称不能为空',
                            trigger:'blur'
                        }
                    ]
                },
                loading:true
            };
        },
        methods:{
            back(){
                this.$router.push("/QueryTCollege")
            }  ,
            submit(formName){
                const _this=this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post('http://localhost:8181/teacher/saveMajor',this.tableData).then(function(resp) {
                            console.log(resp)
                            if (resp.data==='修改成功'){
                                _this.$alert('部门：'+_this.tableData.name+'修改成功', '消息', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        _this.$router.push("/QueryTMajor")
                                    }
                                });
                            }
                        })
                    } else {
                        return false;
                    }
                });
            },
            reset(formName){
                this.$refs[formName].resetFields();
            }
        }
    }
</script>

<style scoped>

</style>
